﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class DepartMentManage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["adminUserName"] == null)
            {
                Response.Redirect("login.aspx");
            }
        }
    }
    protected void Btn_Add_Click(object sender, EventArgs e)
    {
        /*添加新的部门类别*/
        string DepartmentName = this.DeviceTypeName.Text;
        Department dptName = new Department();
        if (dptName.AddDepartMentName(DepartmentName))
            Response.Write("<script>alert('设备新类别信息添加成功!');location.href='DepartMentManage.aspx';</script>");
        else
            Response.Write("<script>alert('" + dptName.ErrMessage + "');</script>");
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //当鼠标选择某行时变颜色
            e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00ffee';");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
            Literal operation = (Literal)(e.Row.Cells[2].FindControl("operation"));
            string deviceTypeId = e.Row.Cells[0].Text;
            operation.Text = "<a href='DepartMentEdit.aspx?departmentId=" + deviceTypeId + "'><img src='images/edit.gif' height=14 width=14 border=0>修改</a>&nbsp;&nbsp;<a href='DepartmentDel.aspx?departmentId=" + deviceTypeId + "'><img src='images/delete.gif' width=14 height=14 border=0>删除</a>";
        }
    }
}
